package com.ptszyxx.popose.module.main.user;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;
import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.constants.BundleConstant;
import com.ptszyxx.popose.common.enums.EditEnum;
import com.ptszyxx.popose.databinding.FragmentUserEditContentBinding;
import com.ptszyxx.popose.module.main.user.vm.UserEditContentVM;
import com.ysg.base.BaseFragment;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.utils.YStringUtil;

/**
 * 用户编辑内容：昵称；个性签名
 */
public class UserEditContentFragment extends BaseFragment<FragmentUserEditContentBinding, UserEditContentVM> {
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_user_edit_content;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public UserEditContentVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(UserEditContentVM.class);
    }

    @Override
    public void initParam() {
        super.initParam();
        Bundle bundle = getArguments();
        if (bundle != null){
            viewModel.userId = bundle.getString(BundleConstant.USER_ID);
            viewModel.input.set(bundle.getString(BundleConstant.CONTENT));
            String edit = bundle.getString(BundleConstant.EDIT_TYPE);
            if (YStringUtil.isNotEmpty(edit)){
                viewModel.editEnum = EditEnum.get(edit);
            }
        }
    }

    @Override
    public void initView() {
        super.initView();
        switch (viewModel.editEnum){
            case name:
                binding.titleBar.setTitle(getResources().getString(R.string.user_edit_title_nick));
                binding.etInput.setHint(getResources().getString(R.string.user_edit_hint_nick));
                break;
            case sign:
                binding.titleBar.setTitle(getResources().getString(R.string.user_edit_title_sign));
                binding.etInput.setHint(getResources().getString(R.string.user_edit_hint_sign));
                break;
            case expression:
                binding.titleBar.setTitle(getResources().getString(R.string.user_edit_title_expression));
                binding.etInput.setHint(getResources().getString(R.string.user_edit_hint_expression));
                break;
        }
    }
}
